# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=h5py
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-$_realname"
         "${MINGW_PACKAGE_PREFIX}-python3-$_realname")
pkgver=2.5.0
pkgrel=2
pkgdesc="General-purpose Python bindings for the HDF5 library (mingw-w64)"
arch=('any')
url="http://www.h5py.org"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-numpy"
             "${MINGW_PACKAGE_PREFIX}-python3-numpy"
             "${MINGW_PACKAGE_PREFIX}-python2-six"
             "${MINGW_PACKAGE_PREFIX}-python3-six"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cython2"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-hdf5"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=(https://pypi.python.org/packages/source/h/h5py/h5py-${pkgver}.tar.gz
        001-mingw-python.patch
        lzf_c.c.patch)
sha256sums=('9833df8a679e108b561670b245bcf9f3a827b10ccb3a5fa1341523852cfac2f6'
            '7c3f6afa82fdb5805c5415e62b0de4e82896986613bdc5e541b53dcc4fa19982'
            '6d0126b881b5dcd637146d151341b72aa68eef760092272279072ec0bc4ceca9')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-mingw-python.patch
  patch -p1 -i ${srcdir}/lzf_c.c.patch
  cd ..

  cp -a ${_realname}-${pkgver} ${_realname}-py2-${pkgver}
  cp -a ${_realname}-${pkgver} ${_realname}-py3-${pkgver}
}

build() {
  # build for python2
  cd ${srcdir}/${_realname}-py2-${pkgver}

  plain "doing setup.py build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py build
  plain "done setup.py build"

  # build for python3
  cd ${srcdir}/${_realname}-py3-${pkgver}

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package_python2-h5py() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-numpy"
           "${MINGW_PACKAGE_PREFIX}-python2-six"
           "${MINGW_PACKAGE_PREFIX}-hdf5")

  cd ${_realname}-py2-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  DISTUTILS_DEBUG=1 ${MINGW_PREFIX}/bin/python2 setup.py install --skip-build \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -Dm644 licenses/license.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE.txt"
}

package_python3-h5py() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-numpy"
           "${MINGW_PACKAGE_PREFIX}-python3-six"
           "${MINGW_PACKAGE_PREFIX}-hdf5")

  cd ${_realname}-py3-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --skip-build \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -Dm644 licenses/license.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE.txt"
}

package_mingw-w64-i686-python2-h5py() {
  package_python2-h5py
}

package_mingw-w64-i686-python3-h5py() {
  package_python3-h5py
}

package_mingw-w64-x86_64-python2-h5py() {
  package_python2-h5py
}

package_mingw-w64-x86_64-python3-h5py() {
  package_python3-h5py
}
